package com.huatai.datadevelop.websocket;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author hecai
 * @description: TODO
 * @date 2023/2/13 14:38
 * @Version 1.0
 */
public class pageAnd {
    private static volatile AtomicInteger onlineCount = new AtomicInteger(1);

    private static Map<String,Integer> onlineMap = new ConcurrentHashMap<String,Integer>();

    /**
     * 数值+1
     * @return
     */
    public static Integer addNumber(){
        onlineCount.incrementAndGet();
        return onlineCount.get();
    }

    /**
     * 数值+1
     * @return
     */
    public static Integer addNumber(String interfaceName){
        Integer value = onlineMap.get(interfaceName);
        value = value+ 1;
        onlineMap.put(interfaceName,value);
        return onlineMap.get(interfaceName);
    }

    /**
     * 数值-1
     * @return
     */
    public static Integer decrement(){
        onlineCount.decrementAndGet();
        return onlineCount.get();
    }

    /**
     * 数值-1
     * @return
     */
    public static Integer decrement(String interfaceName){
        Integer value = onlineMap.get(interfaceName);
        value = value - 1;
        onlineMap.put(interfaceName,value);
        return onlineMap.get(interfaceName);
    }

    /**
     * 重置  从1开始
     * @return
     */
    public static Integer resSet(){
        onlineCount.set(1);
        return onlineCount.get();
    }


    /**
     * 重置  从1开始
     * @return
     */
    public static Integer resSet(String interfaceName){
        onlineMap.put(interfaceName,1);
        return onlineMap.get(interfaceName);
    }

    /**
     * 获取数据
     * @return
     */
    public static Integer getPage(){
        return onlineCount.get();
    }

    /**
     * 获取数据
     * @return
     */
    public static Integer getPage(String interfaceName){
        return onlineMap.get(interfaceName);
    }
}
